package cn.dinghu.pro.service.impl;

import cn.dinghu.pro.common.ResultData;
import cn.dinghu.pro.entity.Orders;
import cn.dinghu.pro.mapper.OrdersMapper;
import cn.dinghu.pro.service.IOrdersService;
import cn.dinghu.pro.utils.Pager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.deploy.ui.AppInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author xibao
 * @since 2025-10-15
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements IOrdersService {
    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public ResultData updateStatus(int status, int id) {
        return ordersMapper.updateStatus(status, id)>0?ResultData.ok_201():ResultData.fail_201();
    }

    @Override
    public ResultData add(Orders orders) {
        return ordersMapper.add(orders)>0?ResultData.ok_201():ResultData.fail_201();
    }

    @Override
    public ResultData edit(Orders orders) {
        return ordersMapper.update(orders)>0?ResultData.ok_201():ResultData.fail_201();
    }

    // 获取列表
    @Override
    public List<Orders> getAppInfoList(Integer userId,String nurseName, String userName, String orderStatus, String category, String phone, Integer pageNo, Integer pageSize) {
        return ordersMapper.getAppInfoList(userId,userName,nurseName,orderStatus,category,phone,(pageNo-1)*pageSize,pageSize);
    }
    // 获取总条数
    @Override
    public int getAppInfoCount(Integer userId,String nurseName, String userName, String orderStatus, String category, String phone) {
        return ordersMapper.getAppInfoCount(userId,nurseName,userName,orderStatus,category,phone);
    }
    // 分页
    @Override
    public ResultData getPageInfo(Integer userId,String nurseName, String userName, String orderStatus, String category, String phone,Integer pageNo, Integer pageSize) {
        Pager<Orders> pager=new Pager<>();
        pager.setPageNo(pageNo);
        pager.setPageSize(pageSize);
        pager.setTotalCount(this.getAppInfoCount(userId,nurseName,userName,orderStatus,category,phone));
        pager.setDataList(this.getAppInfoList(userId,nurseName,userName,orderStatus,category,phone,pageNo,pageSize));

        if (pager.getDataList().size()>0){
            return ResultData.ok(pager);
        }else {
            return ResultData.noData();
        }
    }

    @Override
    public int updatePj(int orderId, int pj) {
        return ordersMapper.updatePj(orderId,pj);
    }
}
